﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TileEngine.items;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace TileEngine.inventory
{
    class Holder
    {
        public List<Iitem> items;
        public Keys hotKey;
        public bool islocked=false;
        public bool canAdd = true;
        public bool isRecipe = false;
        public int count;

        public Rectangle bounds;
        public Holder(Rectangle bounds,int count,Type type)//recipeler için
        {
            items = new List<Iitem>();
            items.Add(Activator.CreateInstance(type) as Iitem);
            this.count = count;
            this.bounds = bounds;
        }
        public Holder(Rectangle bound, Type type)//accessories için falan
        {
        }
        public Holder(Rectangle bounds)
        {
            items = new List<Iitem>();
            this.bounds=bounds;
        }
        public Holder()
        {
            items = new List<Iitem>();
        }
        public bool addItem(Iitem item){
            if (items.Count == 0)
            {
                items.Add(item);
                return true;
            }
            if (item.GetType() == items[0].GetType())
            {
                if (item.getStackMax() <= items.Count)
                    return false;
                items.Add(item);
                return true;
            }

            return false;
        }
        public void setHotkey(Keys hotKey) {
            this.hotKey = hotKey;
        }
        public void draw(SpriteBatch spriteBatch, Rectangle destinationRectangle)
        {
            spriteBatch.Draw(Textures.itemHolder, destinationRectangle, new Color(120, 120, 120, 120));
            if (items.Count != 0)
            {
                spriteBatch.Draw(items[0].getTexture(), destinationRectangle, Color.White);
                if (items.Count != 1)
                    spriteBatch.DrawString(Textures.font8, items.Count.ToString(), new Vector2(destinationRectangle.X + 4, destinationRectangle.Y + 2), Color.Black);
            }
            if (hotKey != Keys.None)
                spriteBatch.DrawString(Textures.font8, hotKey.ToString(), new Vector2(destinationRectangle.X + 4, destinationRectangle.Y + 9), Color.Black);
        }
        public void draw(SpriteBatch spriteBatch, bool isColored)
        {
            if (isColored)
                spriteBatch.Draw(Textures.itemHolder, bounds, new Color(20, 20, 50, 150));
            else
                spriteBatch.Draw(Textures.itemHolder, bounds, new Color(120, 120, 120, 120));
            if (items.Count != 0)
            {
                spriteBatch.Draw(items[0].getTexture(), bounds, Color.White);
                if (items.Count != 1)
                {
                    spriteBatch.DrawString(Textures.font8, items.Count.ToString(), new Vector2(bounds.X + 5, bounds.Y + 3), Color.Black);
                    spriteBatch.DrawString(Textures.font8, items.Count.ToString(), new Vector2(bounds.X + 4, bounds.Y + 2), Color.White);
                }
            }
            if (hotKey != Keys.None)
            {
                spriteBatch.DrawString(Textures.font8, hotKey.ToString(), new Vector2(bounds.X + 5, bounds.Y + 11), Color.Black);
                spriteBatch.DrawString(Textures.font8, hotKey.ToString(), new Vector2(bounds.X + 4, bounds.Y + 10), Color.White);
            }
        }
        public void drawRecipe(SpriteBatch spriteBatch, bool isColored)
        {
            if (isColored)
                spriteBatch.Draw(Textures.itemHolder, bounds, new Color(20, 20, 50, 150));
            else
                spriteBatch.Draw(Textures.itemHolder, bounds, new Color(120, 120, 120, 120));
            spriteBatch.Draw(items[0].getTexture(), bounds, Color.White);
            spriteBatch.DrawString(Textures.font8, count.ToString(), new Vector2(bounds.X + 5, bounds.Y + 3), Color.Black);
            spriteBatch.DrawString(Textures.font8, count.ToString(), new Vector2(bounds.X + 4, bounds.Y + 2), Color.White);
        }
    }
}
